//package com.example.vueblog.interceptor;
//
//import org.slf4j.MDC;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.UUID;
//
///**
// * @author yushunshun
// * @date 2022/7/17 14:43
// */
//@Component
//public class LogInterceptor implements HandlerInterceptor {
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        //如果有上层调用就用上层的ID
//        String traceId = request.getHeader("traceId");
//        if (traceId == null) {
////            traceId = TraceIdUtil.getTraceId();
//            traceId = UUID.randomUUID().toString().replace("-", "");
//        }
//        MDC.put("uri",request.getRequestURI());
//        MDC.put("traceId", traceId);
//        return true;
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
//            throws Exception {
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
//            throws Exception {
//        //调用结束后删除
//        MDC.remove("traceId");
//    }
//}
